﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aiShiShaiFa
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[101];
            //数组赋值,申请多余的空间以满足arr[i]=i
            for (int i = 2; i < arr.Length; i++)
            {
                arr[i] = i;
                //Console.Write(arr[i]+" ");
            }
            //将合数置零
            for (int i = 2; i < arr.Length; i++)
            {
                if (arr[i] != 0)
                {
                    int j, k;
                    k = arr[i];
                    for (j = 2 * k; j < arr.Length; j = j + k)//将数组中K的倍数置零
                    {
                        arr[j] = 0;
                    }
                }
            }
            Console.WriteLine("2-100之间的素数有：");
            for (int i = 2; i < arr.Length; i++)
            {
                if (arr[i] != 0)
                {
                    Console.Write(arr[i] + " ");
                }
            }
            Console.ReadKey();
        }
    }
}
